#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Author: FQ
Module Description: cross_chess ... 
File: cross_chess.py
Date: 2019/5/11
"""
from common.service_config import get_action_id
from pyshare.const.enums.cross_chess import CrossChessPowerLogDict
from pyshare.utils.game_log.game_log_define import CrossChessScoreLog, CrossChessManualLog, CrossChessRoleVitLog, \
    CrossChessRolePassCardNumLog


class CrossChessRoleMixin(object):
    role_guid = NotImplemented
    total_score = NotImplemented
    total_manual = NotImplemented
    srv_id = NotImplemented
    power = NotImplemented
    pass_card_num = NotImplemented

    def total_score_log(self, val):
        """
        个人积分记录日志
        :param val:
        :return:
        """
        add = val - self.total_score
        if add == 0:
            return
        scene = get_action_id()
        try:
            CrossChessScoreLog.log_game(self.role_guid, val, add, scene)
        except:
            pass

    def total_manual_log(self, val):
        """
        个人棋谱记录日志
        :return:
        """
        add = val - self.total_manual
        if add == 0:
            return
        scene = get_action_id()
        try:
            CrossChessManualLog.log_game(self.role_guid, val, add, scene, server_id=self.srv_id)
        except:
            pass

    def role_vit_log(self, val):
        """
        体力日志
        :param val:
        :return:
        """
        add_vit = val - self.power
        scene = get_action_id()
        # 40719为下发数据接口，会进行更新体力但并不保存
        if scene == 40719 or add_vit == 0:
            return
        if add_vit > 0:
            remark = CrossChessPowerLogDict.get(str(scene), '体力自动恢复')
        else:
            remark = CrossChessPowerLogDict.get(str(scene), '获取备注失败')
        try:
            CrossChessRoleVitLog.log_game(self.role_guid, val, add_vit, scene, remark)
        except:
            pass

    def pass_card_num_log(self, val):
        """
        心境值日志
        @param val:
        @return:
        """
        add = val - self.pass_card_num
        if add == 0:
            return
        try:
            CrossChessRolePassCardNumLog.log_game(self.role_guid, val, add)
        except:
            pass